package com.hd.trans.share;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public final class TimeUtils {
    private TimeUtils() {
    }

    public static String getDateToString(long milSecond,  String pattern) {
        final Date date = new Date(milSecond);
        final SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.getDefault());
        return format.format(date);
    }

    public static boolean isOnNextDay(long lastTime) {
        long lastDay = lastTime / (1000 * 60 * 60 * 24);
        long nowDay = System.currentTimeMillis() / (1000 * 60 * 60 * 24);
        if (nowDay > lastDay) {
            return true;
        }
        return false;
    }

    /**
     * 获得当前时间是"时分秒"的时间
     */
    public static String getHMS() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        SimpleDateFormat format = new SimpleDateFormat("HHmmss");
        return format.format(calendar.getTime());
    }

    /**
     * 时间格式化 12:21:33
     *
     * @param ms 毫秒
     * @return
     */
    public static String formatMs(long ms) {
        final Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(ms);
        final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss", Locale.ROOT);
        format.setTimeZone(TimeZone.getTimeZone("GMT+00"));
        return format.format(calendar.getTime());
    }
}
